package com.dcy.common;

import lombok.Data;

/**
 * @author dongcy
 * @date 2024/12/4 13:49
 * @description ResultUtil
 */
@Data
public class ResultUtil<T> {

    //返回码
    private Integer code;

    //返回消息
    private String message;

    private long count = 0;

    //返回数据
    private T data;

    /**
     * 总页数
     */
    private long totalPage = (long) 0;

    public ResultUtil(){}

    // 返回数据
    protected static <T> ResultUtil<T> build(T data) {
        ResultUtil<T> result = new ResultUtil<T>();
        if (data != null)
            result.setData(data);
        return result;
    }

    public static <T> ResultUtil<T> build(T body, ResultEnum resultEnum) {
        ResultUtil<T> result = build(body);
        result.setCode(resultEnum.getCode());
        result.setMessage(resultEnum.getMessage());
        return result;
    }
}
